home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
ext
/
covers
/
lastfm.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
4KB
|
88 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
from os import path
from gi.repository import Soup
from quodlibet.plugins.cover import CoverSourcePlugin, cover_dir
from quodlibet.util.http import download_json
from quodlibet.util.cover.http import HTTPDownloadMixin
from quodlibet.util.path import escape_filename
class LastFMCover(CoverSourcePlugin, HTTPDownloadMixin):
PLUGIN_ID = 'lastfm-cover'
PLUGIN_NAME = _('LastFM cover source')
PLUGIN_DESC = _('Use LastFM database to fetch covers')
PLUGIN_VERSION = '1.0'
def group_by(cls, song):
return song.album_key
group_by = classmethod(group_by)
def priority():
return 0.33
priority = staticmethod(priority)
def cover_path(self):
mbid = self.song.get('musicbrainz_albumid', None)
if mbid:
return path.join(cover_dir, escape_filename(mbid))
return None(LastFMCover, self).cover_path
cover_path = property(cover_path)
def url(self):
_url = 'http://ws.audioscrobbler.com/2.0?method=album.getinfo&' + 'api_key=107db6fd4c1c7f53b1526fafddab2c82&format=json&' + '&artist={artist}&album={album}&mbid={mbid}'
artist = Soup.URI.encode(self.song.get('artist', ''), None)
album = Soup.URI.encode(self.song.get('album', ''), None)
mbid = Soup.URI.encode(self.song.get('musicbrainz_albumid', ''), None)
if artist or album or mbid:
return _url.format(artist = artist, album = album, mbid = mbid)
return None
url = property(url)
def search(self):
if not self.url:
return self.emit('search-complete', [])
msg = None.Message.new('GET', self.url)
download_json(msg, self.cancellable, self.album_data, None)
def album_data(self, message, json, data = None):
if not json:
print_d('Server did not return valid JSON')
return self.emit('search-complete', [])
album = None.get('album', { })
if not album:
print_d('Album data is not available')
return self.emit('search-complete', [])
covers = None((lambda .0: pass)(album['image']))
result = []
for ck in ('mega', 'extralarge'):
if covers.get(ck):
result.append({
'artist': album['artist'],
'album': album['name'],
'cover': covers[ck] })
continue
self.emit('search-complete', result)
def fetch_cover(self):
if not self.url:
return self.fail('Not enough data to get cover from LastFM')
def search_complete(self, res):
self.disconnect(sci)
if res:
self.download(Soup.Message.new('GET', res[0]['cover']))
else:
return self.fail('No cover was found')
sci = self.connect('search-complete', search_complete)
self.search()